<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>原型链继承</title>
    <style></style>
</head>
<body>
    
</body>
</html>
<script>
 // 创建一个people构造函数
    function People(name,age,isMale){
        // 通过new调用构造函数，构造函数中this指向正在创建的对象
        // console.log(this);
        this.name = name;
        this.age = age;
        this.isMale = isMale;
        this.say= function(){
            console.log(this.name+'说Hello！');
        }
    }

    var people= new People('姓名','年龄');
    console.dir(people);
   
    // 2.创建一个Boy构造函数
    // 使用people来构造boy，即让boy继承于people
    function Boy(name,isMale,birthdate){
        People.call(this,name,isMale,birthdate);
    }

    function Temp(name){};
    Temp.prototype = People.prototype;
    var obj = new Temp();
    Boy.prototype = obj;

    Boy.prototype.play = function(game,hours){
        console.log(this.name+'玩'+game+hours+'小时');
    }

    Boy.prototype.constructor = Boy;

    var boy = new Boy('tom',20,true);
    console.dir(boy);
    boy.play('消消乐',2);
    boy.say();


     function Girl(name,isMale,birthdate){
        People.call(this,name,isMale,birthdate);
    }

    function Temp(name){};
    Temp.prototype = People.prototype;
    var obj = new Temp();
    Girl.prototype = obj;

    Girl.prototype.goshopping = function(place,hours){
        console.log(this.name+'去'+place +'逛'+hours+'小时');
    }

    //isLonghair 是在Girl的原型中 ,然后Girl的原型是继承于People的
    Girl.prototype.isLonghair = true;

    Girl.prototype.constructor = girl;

    var girl = new Girl('lili',21,false);
    console.dir(girl);
    girl.goshopping('二七',3);
    girl.say();
   
</script>